package Test;

public class handOut implements Runnable{

    Integer homeWork = 80;

    @Override
    public void run() {
        while (true){
            synchronized (homeWork){
                if (homeWork>0){
                    System.out.println(Thread.currentThread().getName()+
                            "老师正在分发第"+homeWork--+"份学习笔记！");
                    try{
                        Thread.sleep(500);
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    public static void main(String[] args) {

        // 创建资源共享实例对象
        handOut hd = new handOut();
        new Thread(hd,"a老师").start();
        new Thread(hd,"b老师").start();
        new Thread(hd,"c老师").start();

    }

}
